import React, { Component, PureComponent } from 'react'
import PropTypes from 'prop-types'

export default class ParentContext extends Component {
  state = {
    childContext: '123'
  }
  getChildContext() {
    return {
      value: this.state.childContext
    }
  }
  render() {
    console.log('render parent')
    return (
      <div>
        ParentContext
        <input type="text" value={this.state.childContext} onChange={(e) => this.setState({childContext: e.target.value})}/>
        <ChildContext />
        <ChildContext2 />
      </div>
    )
  }
}

class ChildContext extends Component{
  
  render(){
    console.log(this.context)
    console.log('render ChildContext')
    return (
      <div>ChildContext
        {this.context.value}
      </div>
    )
  }
}
class ChildContext2 extends PureComponent{
  
  render(){
    console.log('render ChildContext2')
    return (
      <div>ChildContext2
      </div>
    )
  }
}

ParentContext.childContextTypes = {
  value: PropTypes.string,
}
ChildContext.contextTypes = {
  value: PropTypes.string,
}
